package com.designed.pattern.creational.prototype;

/**
 * @author yifei
 * @date 2024/3/28
 **/
public class Test {
    public static void main(String[] args) throws CloneNotSupportedException {
        //使用原型设计模式创建对象
        Pig peki = new Pig();
        peki.setName("佩琪");
        peki.setDoSomething("喜欢吃蛋糕");
        System.out.println(peki);

        Pig george = (Pig) peki.clone();
        george.setName("乔治");
        george.setDoSomething("喜欢睡觉");
        System.out.println(george);

        Pig pigDad = (Pig) peki.clone();
        pigDad.setName("猪爸爸");
        pigDad.setDoSomething("喜欢开车");
        System.out.println(pigDad);

        Pig pigMum = (Pig) peki.clone();
        pigMum.setName("猪妈妈");
        pigMum.setDoSomething("喜欢做饭");
        System.out.println(pigMum);
    }
}
